﻿namespace Arms.Domain.Modules.Orders
{
    using Arms.Domain.Modules.People;
    using Arms.Domain.Modules.Products;
    using System;
    using System.Collections.Generic;
    using System.Linq;

    public class OrderHeader : Entity
    {
        public OrderHeader()
        {
            this.Orders = new HashSet<Order>();
        }

        #region Properties

        public int OrderHeaderNumber { get; set; }
        public int? CustomerID { get; set; }
        public int? DiningRoomTableID { get; set; }
        public DateTime OrderDate { get; set; }
        public OrderState OrderState
        {
            get
            {
                var orderCount = this.Orders.Count;

                if (this.Orders.Where(x => x.OrderState == OrderState.Closed).Count() == orderCount)
                {
                    return OrderState.Closed;
                }
                else if (this.Orders.Where(x => x.OrderState == OrderState.Invoiced).Count() == orderCount)
                {
                    return OrderState.Invoiced;
                }
                else if (this.Orders.Where(x => x.OrderState == OrderState.Processing).Count() == orderCount)
                {
                    return OrderState.Processing;
                }
                else if (this.Orders.Where(x => x.OrderState == OrderState.Void).Count() == orderCount)
                {
                    return OrderState.Void;
                }
                else
                {
                    return OrderState.Open;
                }
            }
        }

        #endregion

        #region Navigation

        public virtual Customer Customer { get; set; }
        public virtual ICollection<Order> Orders { get; set; }

        #endregion
    }
}